﻿using System.Threading.Tasks;

using ApproveFlowEngine.Blazor.Components.Toolbar.LoginLink;
using ApproveFlowEngine.Blazor.Pages;

using Microsoft.Extensions.DependencyInjection;

using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.Users;

namespace ApproveFlowEngine.Blazor.Menus;

public class ApproveFlowEngineToolbarContributor : IToolbarContributor
{
    #region Public Methods

    public virtual Task ConfigureToolbarAsync(IToolbarConfigurationContext context)
    {
        context.Toolbar.Items.Add(new ToolbarItem(typeof(Approve_Create)));
        if (context.Toolbar.Name != StandardToolbars.Main)
        {
            return Task.CompletedTask;
        }

        if (!context.ServiceProvider.GetRequiredService<ICurrentUser>().IsAuthenticated)
        {
            context.Toolbar.Items.Add(new ToolbarItem(typeof(LoginLinkViewComponent)));
        }

        return Task.CompletedTask;
    }

    #endregion Public Methods
}